
package biblio.dao;


import biblio.domain.Author;
import biblio.exception.NoSuchEntityException;
import java.io.Serializable;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


/**
 * Default implementation of AuthorDAO.
 * @author mephisto
 */
//working with spring 3.0 and higher
//@Bean("authorDAO")
public class AuthorDAOImpl extends HibernateDaoSupport implements AuthorDAO
{

    public void create(Author author)
    {
        getHibernateTemplate().persist(author);
    }

    /**
     * @throws DataAccessException - in case of Hibernate errors
     */
    public List<Author> find(Serializable lastName) throws NoSuchEntityException
    {
        List<Author> res = getHibernateTemplate().findByNamedParam(
                "from Author where lastName = :lastName", "lastName", lastName);
        if (res.isEmpty())
            throw new NoSuchEntityException("No author under lastName " + lastName);
        return res;
    }

    /**
     * @throws DataAccessException - in case of Hibernate errors
     */
    public void update(Author author) throws NoSuchEntityException
    {
        getHibernateTemplate().update(author);
    }

    /**
     * @throws DataAccessException - in case of Hibernate errors
     */
    public void delete(Author author)
    {
        getHibernateTemplate().delete(author);
    }

    /**
     * @throws DataAccessException - in case of Hibernate errors
     */
    public List<Author> selectAll()
    {
        return getHibernateTemplate().find("from Author");
    }
}
